<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page contentType="text/html;charset=UTF-8" %>
<%@ include file="/commons/taglibs.jsp" %>
<html>
<head>
	<script src="${ctx}/includes/jquery.js" type="text/javascript"></script>
	<script src="${ctx}/includes/jquery.validate.js" type="text/javascript"></script>
	<link rel="stylesheet" type="text/css" href="${ctx}/style/form_table.css"></link>
</head>
<body>
<form id="change_user_pwd_form" name="change_user_pwd_form" method="post" action="user/updatePassword.do">
	<table class="form-table">
		<tr>
			<th width="18%" align="right"><span class="note_red">*</span>当前密码：</th>
			<td align="left" valign="middle">
				<input name="pwd" type="password" class="form-txtinput" id="pwd" size="25" maxlength="20">
			</td>
		</tr>
		<tr>
			<th align="right"><span class="note_red">*</span>新密码：</th>
			<td align="left" valign="middle">
				<input name="newpwd" type="password" class="form-txtinput" id="newpwd" size="25" minlength="密码不能小于6个字符">
				<span class="descstyle">&nbsp;长度在6-20之间，不允许包含空格</span>
			</td>
		</tr>
		<tr>
			<th align="right"><span class="note_red">*</span>密码确认：</th>
			<td align="left" valign="middle">
				<input name="repwd" type="password" class="form-txtinput" id="repwd" size="25" minlength="密码不能小于6个字符">
				<span class="descstyle">&nbsp;长度在6-20之间，不允许包含空格</span>
			</td>
		</tr>
	</table>
	<%-- 
	<div class="win-btn-panel">
	     <a class="btn_short" href="javascript:void(0)" onClick="ChangeUserPwdUtils.submitForm()">确 定</a>
	</div>
	--%>
</form>
</body>
<script>
$(function(){
	$("#change_user_pwd_form").validate({
		errorPlacement: function(error, element){
            $(element).next('.field_notice').hide();
            $(element).after(error);
       },
	   success: function(label){   
	       label.addClass('right').text('OK!');
	   },
	   rules:   
	   {
	    	pwd : {required : true},
           	newpwd : {required : true,minlength:6},
           	repwd : {required : true,minlength:6,equalTo: "#newpwd"},
	   },   
	   message:{
	    	pwd : {required : '请输入密码'},
           	newpwd : {required : '请输入新密码',minlength:"密码不能小于6个字符"},
           	repwd : {required : '请输入确认密码',minlength:"确认密码不能小于6个字符",equalTo:"两次输入密码不一致"}
	   },
	   submitHandler: function() {
	   		updateUserSetting();
	   }
	});  
});

function updateUserSetting(){
	var v = $("#change_user_pwd_form").valid();
	if(v){
		var form = $("#change_user_pwd_form");
		var f = form.serialize();
		$.post("${ctx}/user/updatePassword.do", f, function (responseXML) {
			var result = responseXML.getElementsByTagName("result")[0].firstChild.nodeValue;
			var message = responseXML.getElementsByTagName("error-message")[0].firstChild.nodeValue;
			var errorType = responseXML.getElementsByTagName("error-type")[0].firstChild.nodeValue;
			if(!eval(result)&&(errorType!=2)){
				alert(message);
			}
			else{
				alert(message);
				return true;
			}
		});
		return false;
	}
	return false;
}
</script>
